<?php
include_once("../configure/admin.config.inc.php");//--> admin global var
include_once("db.inc.php");						//--> db global var
include_once("Smarty.class.php");				//--> out template
include_once("Operation.php");					//--> Operation
include_once("Menu.php");						//--> Menu
include_once("MenuGroup.php");					//--> MenuGroup
require_once("controlHeader.php");				//--> system control header

$objOperate		= new Operation($objSession->getLanguage());			//--> Operation
$objMenu		= new Menu($objSession->getLanguage(), $uid);			//--> Menu
$objMenuGroup	= new MenuGroup($objSession->getLanguage(), $uid);		//--> MenuGroup

$error_message 	= '';
$strMenuName 	= '';
$strMenuUrl		= '';
$strMenuRemark	= '';
$strGroupID		= '';

$arrOperate = $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);

if(isset($_POST['Submit'])){
	$strGroupID 	= $_POST['groupid'];
	$strOrders 		= $_POST['orders'];
	$strMenuName 	= $_POST['menuName'];
	$strMenuUrl		= $_POST['menuUrl'];
	$strMenuRemark 	= $_POST['menuRemark'];
	
	if(empty($strGroupID))
		$error_message = 'The menu group ID should\'t be empty.';
	else if(empty($strMenuName))
		$error_message = 'The menu name should\'t be empty.';
	else if(empty($strMenuUrl)){
		$error_message = 'The menu url should\'t be empty.';
	}else{
		$isReturn = $objMenu->add($arrOperate, $strGroupID, $strOrders, $strMenuName, $strMenuUrl, $strMenuRemark);
		if($isReturn)
			$error_message = 'add successfully.';
		else 
			$error_message = 'add failure.';
	}
}

$arrMenuGroup = array();
$arrMenuGroupList = $objMenuGroup->lists($arrOperate, '', 1, 100, '');

if(is_array($arrMenuGroupList)){
	foreach ($arrMenuGroupList as $value){
		if($objSession->getLanguage() == "zh-CN"){
			$arrMenuGroup[$value['id']] = $value['namecn'];
		}else
			$arrMenuGroup[$value['id']] = $value['name'];
	}
}

/*----- out html -----*/
$smarty = new Smarty();					//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = CACHE_SYS_DIR;
$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('backurl',$backurl);
$smarty->assign('error_message', $error_message);

$smarty->assign('arrMenuGroup', $arrMenuGroup);
$smarty->assign('groupidS', $strGroupID);
$smarty->assign('orders', $strOrders);
$smarty->assign('menuName', $strMenuName);
$smarty->assign('menuUrl', $strMenuUrl);
$smarty->assign('menuRemark', $strMenuRemark);

$smarty->display('listMenu_Add.htm');
?>
